package cn.kgc.utils;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;

/**
 * @author k
 */
@SuppressWarnings("all")
public class PagedGridResult {
	/**
	 * 当前页数
	 */
	private long page;
	/**
	 * 总页数
	 */
	private long total;
	/**
	 * 总记录数
	 */
	private long records;
	/**
	 * 每页显示的内容
	 */
	private List<?> rows;


	public long getPage() {
		return page;
	}
	public void setPage(long page) {
		this.page = page;
	}

	/**
	 * 设置每页显示条数,计算出总页数
	 */
	public void setPageSize(long pageSize){
		if(pageSize<0){
			pageSize=10;
		}
		total=(records%pageSize==0)?(records/pageSize):(records/pageSize+1);
	}

	public long getTotal() {
		return total;
	}


	public long getRecords() {
		return records;
	}

	public void setRecords(long records) {
		this.records = records;
	}

	public List<?> getRows() {
		return rows;
	}

	public void setRows(List<?> rows) {
		this.rows = rows;
	}

    /**
     * 将MyBatisPlus的分页结果封装成PageGridResult
     */
    public static PagedGridResult setterPagedGrid(Page page){
        PagedGridResult gridResult = new PagedGridResult();
        gridResult.setRows(page.getRecords());
        gridResult.setPage(page.getCurrent());
        gridResult.setRecords(page.getTotal());
        gridResult.setPageSize(page.getSize());
        return gridResult;
    }
}